package com.campus.controller;

import com.campus.service.IUserService;
import com.campus.utils.JWTUtil;
import com.campus.utils.R;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private IUserService iUserService;


    @PostMapping("/login")
    public R login(Integer id, String password) {

        if (iUserService.login(id, password) == 1) {
            return R.success("登录成功", JWTUtil.createToken(id));
        } else {
            return R.error("登录失败");
        }
    }

    @PostMapping("/create")
    public R create(Integer id, String loginName, String password, String gender, String birthday, String phone, String email, String status)
    {
        return R.success(iUserService.creatUser(id, loginName, password, gender, birthday, phone, email, status));
    }


    @GetMapping("/query")
    public R query(Integer id,String loginName)
    {
        return R.success("查询成功",iUserService.query(id, loginName));
    }
}
